package com.city.repository.report.format;

import com.city.domain.report.format.CtUserFoemat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CtUserFoematRepository extends JpaRepository<CtUserFoemat,Integer> {

    @Query(value = "SELECT c.user_id id ,c.user_id user_id , c.branch_id branch_id ," +
            "u.name name ,u.password password , u.is_manager is_manager ," +
            "b.name branch_name from ct_user_branch as c " +
            "LEFT JOIN ct_user as u on c.user_id = u.id " +
            "LEFT join ct_branch as b on c.branch_id = b.id limit ?1,?2",nativeQuery = true)
    List<CtUserFoemat> findByPage(Integer page,Integer limit);


    @Query(value = "SELECT c.user_id id ,c.user_id user_id , c.branch_id branch_id ," +
            "u.name name ,u.password password ,  u.is_manager is_manager , " +
            "b.name branch_name from ct_user_branch as c " +
            "LEFT JOIN ct_user as u on c.user_id = u.id " +
            "LEFT join ct_branch as b on c.branch_id = b.id where c.branch_id = ?1 ",nativeQuery = true)
    List<CtUserFoemat> findByBranchId(Integer branchId);

    @Query(value = "SELECT c.user_id id ,c.user_id user_id , c.branch_id branch_id ," +
            "u.name name ,u.password password ,  u.is_manager is_manager , " +
            "b.name branch_name from ct_user_branch as c " +
            "LEFT JOIN ct_user as u on c.user_id = u.id " +
            "LEFT join ct_branch as b on c.branch_id = b.id where c.user_id = ?1 ",nativeQuery = true)
    CtUserFoemat findByUserId(Integer userId);
}
